<template>
  <el-form :model="detailForm" ref="detailForm" :inline="false"
           :class="isEdit?'':'formItem'" label-position="labelPosition">

    <!-- 其他费用 -->
    <el-card class="box-card" shadow="never">

      <div slot="header" class="header-card">
        <span class="header-card-title">其他费用</span>
      </div>

      <el-row :gutter="24">
        <el-col :span="8">
          <el-form-item label="其他费用:" prop="otherPrice">
            <el-input v-model="detailForm.otherPrice" v-if="isEdit"
                      @change="changeAmount('otherPrice')"  v-thousand
                      placeholder="请输入其他费用"></el-input>
            <span v-else>{{ format_thousand(detailForm.otherPrice) }}</span>
          </el-form-item>
        </el-col>

        <el-col :span="8">
          <el-form-item label="其他费用产生原因:" prop="otherCostReason">
            <el-input v-model="detailForm.otherCostReason" v-if="isEdit"
                      placeholder="请输入其他费用产生原因"></el-input>
            <span v-else>{{ detailForm.otherCostReason }}</span>
          </el-form-item>
        </el-col>

        <el-col>
          <el-form-item label="其他费用产生附件:">
            <ImageCommon v-model="detailForm.otherCostUrl" :limit="1" :disabled="!isEdit" :upType="2"/>
          </el-form-item>
        </el-col>

      </el-row>
    </el-card>

  </el-form>
</template>

<script>
export default {
  name: 'other',//其他费用
  props: {
    value: {
      type: Object,
      default: {},
    },
    state: {
      type: String,
      default: "",
    }
  },

  computed: {
    detailForm: {
      get() {
        let that = this;
        const proxy = new Proxy(that.value, {
          get(target, key) {
            return Reflect.get(target, key);
          },
          set(target, key, value) {
            that.$emit("input", {...target, [key]: value});
            return true;
          },
        });
        return proxy;
      },
    },
    labelPosition() {
      if (this.isEdit) {
        return 'top'
      } else {
        return 'right'
      }
    },
    isEdit() {
      let bool;
      switch (this.state) {
        case "write":
          bool = true;
          break;
        case "disabled":
          bool = false;
          break;
        case "readonly":
          bool = false;
          break;
      }
      return bool
    },
  },
  data() {
    return {};
  },
  created() {
  },
  mounted() {
  },
  methods: {
    changeAmount(str) {
      let msg = /^(?:[1-9]\d*|0)(?:\.\d+)?$/
      if (!msg.test(this.value[str])) {
        this.value[str] = ""
      } else {
        this.value[str] = this.value[str].toString().match(/^\d+(?:\.\d{0,2})?/)[0]
      }
    },
  },
};
</script>

<style lang="scss" scoped>
@import "@/styles/cwgd/formScss.scss";
</style>



